var uiRootView = document.body;
var toolRootView;
var uiWidth = 0;
var uiHeight = 0;
var uiPixelDepth = 0;

var CurrentTheme = "Default";
var CurrentThemeIconPath = rootPath+"/system/themes/default/icons";
var DefaultIconPath = rootPath+"/system/graphics/branding";

function Point(x,y)
{
    this.x = x;
    this.y = y;
};

function Rect (x,y,w,h) 
{
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
};

function Icon (frame, srcImage,name)
{
};

function uiInit(x,y,w,h)
{
    loadLock++;
    //uiRootView.innerHTML = "";
    uiWidth = uiRootView.clientWidth;
    uiHeight = uiRootView.clientHeight;
    uiRootView.style.backgroundColor = "#000000"; 
    uiRootView.style.overflow = "hidden";    
    
    uiPixelDepth = 24; 

    toolRootView = document.createElement("div");
    toolRootView.style.position = "absolute";    
    toolRootView.className = 'toolbarView';
    toolRootView.style.left = 0;   
    toolRootView.style.top = 0;
    toolRootView.style.width = uiWidth;
    toolRootView.style.height = 40; 
    toolRootView.style.backgroundColor = "#9e9e9e"; 
    toolRootView.style.overflow = "hidden";        
    uiRootView.appendChild(toolRootView);    
    systemToolBar(toolRootView);
    
    appRootView = document.createElement("div");
    appRootView.style.position = "absolute";    
    appRootView.className = 'appView';
    appRootView.style.left = 0;   
    appRootView.style.top = 41;
    appRootView.style.width = uiWidth;
    appRootView.style.height = uiHeight - 40; 
    uiRootView.appendChild(appRootView);
    
    flipLock();
    return;
};

function View(frame,name)
{
    this.myID = document.createElement("div");
    this.myID.style.position = "absolute";
    
    this.attach = function(parentView)
    {
        parentView.appendChild(this.myID);
    };
    
    this.getID = function()
    {
        return this.myID;
    };
};

function systemToolBar(view)
{
    toolTitleView = document.createElement("div");
    toolTitleView.style.position = "absolute";    
    toolTitleView.className = 'toolbarTitleView';
    toolTitleView.style.left = 5;   
    toolTitleView.style.top = 5;
    toolTitleView.style.width = 100;//uiWidth;
    toolTitleView.style.height = 40; 
    toolTitleView.style.backgroundColor = "#9e9e9e"; 
    toolTitleView.style.overflow = "hidden"; 
    toolTitleView.innerHTML =  "<img height=30 src=\""+rootPath+"/system/graphics/branding/softsurve.png\" >";
    toolTitleView.onclick = toolbarButton;       
    view.appendChild(toolTitleView); 

};

function systemSettings()
{
    toolTitleView = document.createElement("div");
    toolTitleView.style.position = "absolute";    
    toolTitleView.className = 'settingsView';
    toolTitleView.style.left = 50;   
    toolTitleView.style.top = 50;
    toolTitleView.style.width = uiWidth - 50;
    toolTitleView.style.height =uiHeight - 50; 
    toolTitleView.style.backgroundColor = "#9e9e9e"; 
    toolTitleView.style.overflow = "hidden"; 
    toolTitleView.innerHTML = "<h3 System Settings</h3>";       
    appRootView.innerHTML = "Settings View"; //appendChild(toolTitleView);    
};




var fakeDiv = document.createElement("div");

var iconBounce = function(icon)
{
    prefsApp();
};

var iconDyn = function()
{
	alert("???");
};

var BIcon = function(x,y,name,path,callback)
{
    this.myDiv;
    this.myPath = path;
    this.myName = name;
    this.myCallback = callback;
	this.x = x;
	this.y = y;
	
    this.Attach = function(view)
    {
        this.myDiv = document.createElement("div");
        this.myDiv.innerHTML = "<div onclick=\""+this.myCallback+"\"   ><img src=\""+path + "\" width=\"50px\"> </div>"+name+"</div>";
        this.myDiv.style.position = "absolute"; 
        this.myDiv.style.overflow = "hidden";   
        this.myDiv.style.left = this.x;
        this.myDiv.style.top = this.y;
        this.myDiv.style.width = 53;
        this.myDiv.style.font = 6;
        this.myDiv.style.height = 65;    
        this.myDiv.style.color = "white";
		
        view.appendChild(this.myDiv);
    };
    
    this.Action = function(myCallback)
    {
        this.myCallback = myCallback;
    };
};

var DownloadDialog = function()
{
    this.myWindow;
	
    this.init = function()
    {
        aFrame = new BFrame(100,100,500,500);
        this.myWindow = new BDirectWindow(aFrame,"File Select",0,0);
        
    };
	
    this.Run = funtion()
    {
		
        return -1;
    };
};


